class Talk extends PIXI.Container {
	constructor(uimanager, talker, context, option, callback) {
		super();

		this.uimanager = uimanager;
		this.callback = callback;

		// 创建对话框
		const frame = new PIXI.smooth.SmoothGraphics();
		frame.beginFill(0x686028, 1);
		frame.lineStyle({ color: 0x181818, width: 1, alignment: 0 });
		frame.drawRoundedRect(0,0,460,100,50);
		frame.beginFill(0xE0E0C0, 1);
		frame.lineStyle({ color: 0x686028, width: 0, alignment: 0 });
		frame.drawRoundedRect(2,2,460-4,100-4,50);
		frame.endFill();

		frame.position.set(uimanager.realScreen.width - 410, 50);

		// 设置对话位置	
		const richText = new PIXI.Text(context, talkStyle);
		richText.x = 0;
		richText.y = 0;
		richText.resolution = 2;
		richText.position.set(frame.position.x + 30, frame.position.y + 10);

		// 得到talker半身像
		const avater = PIXI.Texture.from(talker.avater);
		const spriteImage = new PIXI.Sprite(avater);
		spriteImage.x = uimanager.realScreen.width - 156;

		// 添加按下button
		const button = new Button("z", {width:24,height:18}, 0xA4A484);
		button.x = uimanager.realScreen.width - 200;
		button.y = 128;
		
		// 添加一个对话框容器
		this.addChild(frame);
		this.addChild(richText);	
		this.addChild(spriteImage);	
		this.addChild(button);	
		this.uimanager.addChild(this);
	}

	end () {
		if (this.callback) this.callback(this);
		this.uimanager.removeChild(this);
	}

	keyDown(key) {
		if(key == "z") {
			this.end();
		}
	}
} 